package com.zijin;

import com.zijin.Dao.AnswerMapper;
import com.zijin.Dao.EmpMapper;
import com.zijin.Dao.QuestionMapper;
import com.zijin.Dao.UserMapper;
import com.zijin.entity.Answer;
import com.zijin.entity.Question;
import com.zijin.entity.User;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.util.List;

public class Test {
    public static void main(String[] args) {
        SqlSessionFactory ssf = new SqlSessionFactoryBuilder().build(
                App.class.getClassLoader().getResourceAsStream("mybatisConf.xml"));
//打开一个会话 ，会话会占用资源，不需要时要关闭
        SqlSession ss = ssf.openSession();
        //获得EmpMapper接口实现类
        //UserMapper userMapper = ss.getMapper(UserMapper.class);//获得动态代理

        //添加用户
        //int user=userMapper.insertUser(new User(3,"lly","123456"));
        //System.out.println(user);

        //查询用户
        //User user = userMapper.selectUser("swy","123456");
        //System.out.println(user);

        //根据用户编号查询用户
        //User user = userMapper.selectUserById(1);
        //System.out.println(user);

        //根据用户编号更新用户消息,修改密码
        //Integer user= userMapper.updateUser(1,"88888888");
        //System.out.println(user);

        //QuestionMapper questionMapper = ss.getMapper(QuestionMapper.class);
        //添加一个问题
        //Integer question=questionMapper.insertQuestion(new Question(3,"ss",1,"2003-5-8",1));
        //System.out.println(question);

        // 查询指定id的所有问题
        //List<Question> list=questionMapper.selectQuestionById(1);
        //System.out.println(list);

        //查询指定问题状态
        //Question question = questionMapper.selectQuestionByQid(1);
        //System.out.println(question);

        //查询指定状态的问题
        //List<Question> list=questionMapper.selectQuestionByQstatus(1);
        //System.out.println(list);

        //查询有回答的问题（多表查询）
        //List<Question> list=questionMapper.selectQuestionByQidAndAnswer(1);
        //System.out.println(list);

        AnswerMapper answerMapper = ss.getMapper(AnswerMapper.class);
        //根据问题编号查询回答内容
        //List<Answer> answer = answerMapper.getAnswerByQuestionId(1);
        //System.out.println(answer);

        //根据用户编号查询回答内容
        //List<Answer> answer=answerMapper.getAnswerByUserId(1);
        //System.out.println(answer);

        //查询问题的状态
        Answer answer=answerMapper.getAnswerByAid(1);
        System.out.println(answer);


    }
}